<template>
	<view>
		<!-- 输入金额 -->
		<u-row customStyle="margin-bottom: 10px;margin-top: 20px">
			<u-col span="1"></u-col>
			<u-col span="10">
				<u--input
				    placeholder="请输入金额"
				    border="surround"
					type="number"
				    v-model="money"
				  ></u--input>
			</u-col>
			<u-col span="1"></u-col>
		</u-row>
		<!-- 卡类型 -->
		<u-row customStyle="margin-bottom: 10px">
			<u-col span="1"></u-col>
			<u-col span="10">
				<u--input
					disabled
				    border="surround"
				    value="校园卡"
				  ></u--input>
			</u-col>
			<u-col span="1"></u-col>
		</u-row>
		<!-- 校园卡密码 -->
		<u-row customStyle="margin-bottom: 10px">
			<u-col span="1"></u-col>
			<u-col span="10">
				<u--input
				    placeholder="请输入校园卡密码"
				    border="surround"
				    type="text"
				    v-model="pwd"
				  ></u--input>
			</u-col>
			<u-col span="1"></u-col>
		</u-row>
		<!-- 按钮 -->
		<u-row customStyle="margin-bottom: 10px">
			<u-col span="1"></u-col>
			<u-col span="10">
				<u-button :disabled="isButton" type="primary" text="充值" @click="submitMoney"></u-button>
			</u-col>
			<u-col span="1"></u-col>
		</u-row>
		<!-- 重度提示 -->
		<u-row customStyle="margin-bottom: 10px">
			<u-col span="1"></u-col>
			<u-col span="10">
				<u-alert title="注意:单笔转账不能超过190元\n转账成功后可在首页 下拉刷新 查看进度." type = "error"></u-alert>
			</u-col>
			<u-col span="1"></u-col>
		</u-row>
		<!-- 提示 -->
		<u-row>
			<u-col span="1"></u-col>
			<u-col span="10">
				<uni-notice-bar text="向校园卡转账成功后,所转金额都会先是在过渡金额中,在餐厅等处的卡机上进行刷卡操作后,过渡余额即会转入校园卡"></uni-notice-bar>
			</u-col>
			<u-col span="1"></u-col>
		</u-row>
		<!-- 提示 -->
		<u-row customStyle="margin-bottom: 10px">
			<u-col span="1"></u-col>
			<u-col span="10">
				<uni-notice-bar text="向校园卡转账成功后,数据可能会有1-2小时的延迟,如未到账!请耐心等待~"></uni-notice-bar>
			</u-col>
			<u-col span="1"></u-col>
		</u-row>
	</view>
</template>

<script>
	import {mixin} from '../../../mixin.js'
	export default {
		data() {
			return {
				money:'',
				pwd:''
			}
		},
		mixins:[mixin],
		computed:{
			isButton(){
				if(this.money < 190 && this.money > 0 && this.pwd !=''){
					return false
				}else{
					return true
				}
				
				
			}
		},
		watch:{
			money(){
				if((this.money > 190 || this.money <= 0) && this.money != ''){
					this.money = ''
					uni.hideKeyboard()
					uni.showToast({
						title:"请输入符合规定的金额",
						position:'bottom'
					})
				}
			}
		},
		onLoad() {
			
		},
		methods: {
			submitMoney(){
				//获取时间戳并转md5
				//let sign = MD5(Number(new Date()))
				//console.log(sign)
				
				//获取用户密码
				let pwd = this.getDes(this.pwd)
				//获取用户msg
				let msg =uni.getStorageSync("msg")

				// 获取用户所充金额
				let money = this.money
				if(money>190 || money<=0)
					return 0;
				//定义拼接字符串
				const params = {
					'amount':money,
					'clienttype':"Android",
					"iplanetdirectorypro": msg,
					'password':pwd,
					'schoolcode':'ccufe',
					'toaccount':"card"
				}
				uni.showModal({
					title:'确定充值?',
					success:res=>{
						if(res.confirm){
							//进行转账网络请求
							uni.showLoading({
								title:"勿动！正在充值中...",
								mask:true
							});
							uni.request({
								url:'http://ykt.ccufe.com:8070/Api/Card/BankTransferPlus',
								method:"POST",
								header:{
									//'User-Agent':'Dalvik/2.1.0 (Linux; U; Android 12; DBY-W09 Build/HUAWEIDBY-W09)',
									'Cache-Control':'no-cache',
									'Accept':'*/*',
									'Accept-Encoding':'gzip, deflate, br',
									'Connection':'keep-alive',
									//'cookie':'ASP.NET_SessionId=4xpnhnbiy1zviro0fsnh4xfb; path=/; HttpOnly; SameSite=Lax',
									'Content-Type':'application/x-www-form-urlencoded',
									'Content-Length':'154'
								},
								data:{
									'amount':money,
									'clienttype':"Android",
									"iplanetdirectorypro": msg,
									'password':pwd,
									'schoolcode':'ccufe',
									'toaccount':"card",
									'sign':this.getMd5(this.getObjToStr(params))
								},
								success:res=>{
									if(res.data.success==false || res.data.success=='false'){
										uni.showModal({
											content:'未登录或登录已失效',
											showCancel:false,
										})
									}
									console.log(res)
										uni.hideLoading();
										uni.showModal({
											content:res.data.msg,
											showCancel:false,
										})
										this.money = ''
										this.pwd = ''
								},
								fail:err=>{
									uni.showToast({
										title:"网络请求错误"
									})
								},
								complete:()=>{
									uni.hideLoading();
									this.money = ''
									this.pwd = ''
								}
							})
							///
						}
					}
				})
				
			}
		}
	}
</script>

<style lang="scss">

</style>
